package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.log.CoolOperLog;
import cn.da.shuai.cool.system.service.service.ICoolOperLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志记录
 */
@RestController
@RequestMapping("/monitor/operlog")
@Tag(name = "操作日志控制器")
public class CoolOperLogController {

    @Autowired
    private ICoolOperLogService operLogService;

    @GetMapping("/list")
    @Operation(summary = "获取操作日志列表")
    public R<List<CoolOperLog>> list(CoolOperLog operLog) {
        List<CoolOperLog> list = operLogService.selectOperLogList(operLog);
        return R.ok(list);
    }

    @GetMapping("/page")
    @Operation(summary = "获取操作日志分页列表")
    public R<Page<CoolOperLog>> page(CoolOperLog operLog, Page<CoolOperLog> page) {
        Page<CoolOperLog> list = operLogService.selectOperLogPage(operLog, page);
        return R.ok(list);
    }

    @DeleteMapping("/{operIds}")
    @Operation(summary = "删除操作日志")
    public R<Void> remove(@PathVariable Long[] operIds) {
        operLogService.deleteOperLogByIds(operIds);
        return R.ok();
    }

    @DeleteMapping("/clean")
    @Operation(summary = "清空操作日志")
    public R<Void> clean() {
        operLogService.cleanOperLog();
        return R.ok();
    }

    @GetMapping("/{operId}")
    @Operation(summary = "根据日志编号获取详细信息")
    public R<CoolOperLog> getInfo(@PathVariable Long operId) {
        return R.ok(operLogService.selectOperLogById(operId));
    }
}